
//下拉菜单
$(document).ready(function(){
    $("#shiju1").click(function(){
        $("#ul_select1").slideToggle("slow");
        $("#ul_select2").fadeOut("fast");
        $("#ul_select3").fadeOut("fast");
        $("#ul_select4").fadeOut("fast");
        $('#shiju2 > .shiju_lf').text("请选择");
        $('#shiju4 > .shiju_lf').text("请选择");
        $("#pcs").val("");
    });
    var selecttext = $('#shiju1 > .shiju_lf');
    var selectmain = $('#ul_select1');
    var lis=selectmain.find('li');
    for(var i=0;i<lis.length;i++)
    {
        lis[i].onclick=function(){
            $("#ul_select2").empty();
            $("#ul_select4").empty();
            var v=$(this).attr("value");
            searchNext(v,2);
            $("#sj").val(v);
            var textval = $(this).html();
            selectmain.hide();
            selecttext.text(decodeURIComponent(textval));
        }
    }
    $("#ul_select1 > li").click(function(){
        $("#ul_select1").slideUp("slow");
        $("#ul_select2").fadeOut("fast");
        $("#ul_select4").fadeOut("fast");
        $("#fj").val("");
        $("#pcs").val("");
    });
});
$(document).ready(function(){
    $("#shiju2").click(function(){
        $("#ul_select2").slideToggle("slow");
        $("#ul_select1").fadeOut("fast");
        $("#ul_select3").fadeOut("fast");
        $("#ul_select4").fadeOut("fast");
        $('#shiju4 > .shiju_lf').text("请选择");
        $("#pcs").val("");
    });
    var selecttext = $('#shiju2 > .shiju_lf');
    var selectmain = $('#ul_select2');
    var lis=selectmain.find('li');
    for(var i=0;i<lis.length;i++)
    {
        lis[i].onclick=function(){
            var v=$(this).attr("value");
            searchNext(v,530);
            var textval = $(this).html();
            selectmain.hide();
            selecttext.text(decodeURIComponent(textval));
        }
    }
    $("#ul_select2 > li").click(function(){
        $("#ul_select2").slideUp("slow");
        $("#ul_select4").fadeOut("fast");
        $("#ul_select1").fadeOut("fast");
        $("#pcs").val("");
    });
});
$(document).ready(function(){
    $("#shiju3").click(function(){
        $("#ul_select3").slideToggle("slow");
        $("#ul_select1").fadeOut("fast");
        $("#ul_select2").fadeOut("fast");
    });
    var selecttext = $('#shiju3 > .shiju_lf');
    var selectmain = $('#ul_select3');
    var lis=selectmain.find('li');
    for(var i=0;i<lis.length;i++)
    {
        lis[i].onclick=function(){
            var textval = $(this).html();
            selectmain.hide();
            selecttext.text(decodeURIComponent(textval));
        }
    }
    $("#ul_select3 > li").click(function(){
        $("#ul_select3").slideUp("slow");
    });
    //事项中心
    $("#shiju_sxzx").click(function(){
        $("#ul_select_sxzx").slideToggle("slow");
    });
    var selecttext11 = $('#shiju_sxzx > .select1_main');
    var selectmain11 = $('#ul_select_sxzx');
    var lis=selectmain11.find('li');
    for(var i=0;i<lis.length;i++)
    {
        lis[i].onclick=function(){
            var textval11 = $(this).html();
//							selectmain.hide();
            selecttext11.text(decodeURIComponent(textval11));
        }
    }
    $("#ui-radio input").click(function(){
        $("#ul_select_sxzx").slideUp("slow");
    });

//婴儿落户下拉

    $("#spbm").click(function(){
        $("#ul_spbm1").slideToggle("slow");
    });
//市局
    var selecttext22 = $('.ul_top_li1');
    var selectmain22 = $('.ul_spbm1_li1');
    var lis=selectmain22.find('li');
    for(var i=0;i<lis.length;i++)
    {
        lis[i].onclick=function(){
            var textval22 = $(this).html();
//							selectmain.hide();
            selecttext22.text(decodeURIComponent(textval22));
        }
    }
//区县
    var selecttext1 = $('.ul_top_li2');
    var selectmain1 = $('.ul_spbm1_li2');
    var lis=selectmain1.find('li');
    for(var i=0;i<lis.length;i++)
    {
        lis[i].onclick=function(){
            var textval1 = $(this).html();
//							selectmain.hide();
            selecttext1.text(decodeURIComponent(textval1));
        }
    }
//派出所
    var selecttext2 = $('#spbm  .shiju_lf');
    var selecttext3 = $('.ul_top_li3');
    //（添加新地址）
    var selecttext4 = $('#tjxdz_xzdq');
    //我的出租屋
    var selecttext5 = $('#wdczw_dqxz1');
    var selectmain2 = $('.ul_spbm1_li3');
    var lis=selectmain2.find('li');
    for(var i=0;i<lis.length;i++)
    {
        lis[i].onclick=function(){
            var textval2 = $(this).html();
//							selectmain.hide();
            selecttext2.text(decodeURIComponent(textval2));
            selecttext3.text(decodeURIComponent(textval2));
            selecttext4.text(decodeURIComponent(selecttext22.html() +selecttext1.html() + textval2));
            selecttext5.text(decodeURIComponent(selecttext22.html() +selecttext1.html() + textval2));
        }
    }


//市局
    $(".ul_spbm1_li1 > li").click(function(){
        $(".ul_spbm1_li1").animate({left:'-100%'});
        $(".ul_spbm1_li2").animate({left:'0'});
        $(".ul_top_li2").css("display","block");
        $(".ul_top_li1").css("color","#000");
    });
//区县
    $(".ul_spbm1_li2 > li").click(function(){
        $(".ul_spbm1_li2").animate({left:'-100%'});
        $(".ul_spbm1_li3").animate({left:'0'});
        $(".ul_top_li3").css("display","block");
        $(".ul_top_li2").css("color","#000");
    });
//派出所
    $(".ul_spbm1_li3 > li").click(function(){
        $(".ywlh_xiala").slideUp();
        $(".ul_top_li3").css("color","#000");

    });
    $(".ul_top_li3").click(function(){
        $(".ul_spbm1_li3").animate({left:'0'});
        $(".ul_spbm1_li2").animate({left:'-100%'});
        $(".ul_spbm1_li1").animate({left:'-100%'});
        $(".ul_top_li3").css("color","#F80000");
        $(".ul_top_li1").css("color","#000");
        $(".ul_top_li2").css("color","#000");
    });
    $(".ul_top_li2").click(function(){
        $(".ul_spbm1_li2").animate({left:'0'});
        $(".ul_spbm1_li3").animate({left:'100%'});
        $(".ul_top_li3").css("color","#000");
        $(".ul_top_li1").css("color","#000");
        $(".ul_top_li2").css("color","#F80000");
    });
    $(".ul_top_li1").click(function(){
        $(".ul_spbm1_li1").animate({left:'0'});
        $(".ul_spbm1_li2").animate({left:'100%'});
        $(".ul_spbm1_li3").animate({left:'100%'});
        $(".ul_top_li3").css("color","#000");
        $(".ul_top_li1").css("color","#F80000");
        $(".ul_top_li2").css("color","#000");

    });
    //出租屋信息登记

    $("#shiju4").click(function(){
        $("#ul_select4").slideToggle("slow");
        $("#ul_select1").fadeOut("fast");
        $("#ul_select2").fadeOut("fast");
    });
    var selecttext = $('#shiju4 > .shiju_lf');
    var selectmain = $('#ul_select4');
    var lis=selectmain.find('li');
    for(var i=0;i<lis.length;i++)
    {
        lis[i].onclick=function(){
            var v=$(this).attr("value");
            $("#pcs").val(v);
            var textval = $(this).html();
            selectmain.hide();
            selecttext.text(decodeURIComponent(textval));
        }
    }
    $("#ul_select4 > li").click(function(){
        $("#ul_select4").slideUp("slow");
    });

    $("#ycz").click(function(){
        $("#yicz").css("display","block");
    });
    $("#wcz").click(function(){
        $("#yicz").css("display","none");
    });
    $(".tjzyry_add").click(function(){
        $(".tjzyry").css("display","block");
    });
    $(".tjzyry_del").click(function(){
        $(".tjzyry").css("display","none");
    });
//出租屋信息
   /* $(".bjsc > .bj").click(function(){
        $("#czwxx").animate({left:'-100%'});
        $("#zkxxbj").css("display","block").animate({left:'0'});
    });
    $("#zjzk").click(function(){
        $("#czwxx").animate({left:'-100%'});
        $("#add_zuke").css("display","block").animate({left:'0'});
    });
    $(".ui-btn-wrap").click(function(){
        $("#czwxx").animate({left:'0'});
        $("#add_zuke").animate({left:'100%'}).css("display","none");
        $("#zkxxbj").animate({left:'100%'}).css("display","none");
    });*/
    //删除
    $(".sc").click(function(){
        $(this).parents(".czwxx_wrapper").css("display","none");
    });
    $(".sc").click(function(){
        $(this).parents(".zfdz").css("display","none");
    });
    //我的出租屋
//			 var selecttext22 = $('.ul_top_li1');
//					var selectmain = $('#ul_select4');
//					var lis=selectmain.find('li');
//					for(var i=0;i<lis.length;i++)
//					{
//						lis[i].onclick=function(){
//							var textval = $(this).html();
//							selectmain.hide();
//							selecttext.text(decodeURIComponent(textval));
//						}
//					}
    $("#wdczw_btn").click(function(){
        $("#wdczw").animate({left:'-100%'});
        $("#wdczwxz").css("display","block").animate({left:'0'});
    });
    $("#wdczwxz_i").click(function(){
        $("#wdczw").animate({left:'0'});
        $("#wdczwxz").css("display","none").animate({left:'100%'});
    });
    $("#ui-btn-lg").click(function(){
        $("#wdczw").animate({left:'0'});
        $("#wdczwxz").css("display","none").animate({left:'100%'});
        $(".wdczw").addClass("zfdz2");
        $(".zfdz1").removeClass("zfdz2");
    });
    $(".bj").click(function(){
        $("#wdczw").animate({left:'-100%'});
        $("#wdczwxz").css("display","block").animate({left:'0'});
    });
    $("#xinzeng").click(function(){
        $("#wdczw").animate({left:'-100%'});
        $("#wdczwxz").css("display","block").animate({left:'0'});z
    });

});
function searchNext(parentCode,stype){
    $.ajax({
        url :uploadUrl+"/api/v2/xrxq/getDept/"+stype+"/"+parentCode,
        type : "get",
        dataType : "json",
        success : function(resp){
            if(resp&&resp.succ){
                var _data = resp.data;
                var _html="";
                if(_data==null || _data==""){
                    if(stype=='530'){
                        $("#special4").hide();
                        $("#select4").hide();
                        $("#pcs").val(parentCode);
                    }else{
                        $("#specail").hide();
                        $("#select2").hide();
                        $("#special4").show();
                        $("#select4").show();
                        mark=1;
                        specilDept(parentCode,530);
                    }
                }else{
                    mark=0;
                    $("#special4").show();
                    $("#select4").show();
                    $("#specail").show();
                    $("#select2").show();
                    for(var i=0;i<_data.length;i++){
                        var _item = _data[i];
                        _html += "<li value='"+_item.guid+"'>" + _item.orgName + "</li>"
                    }
                    if(stype=='2'){
                        $("#ul_select2").empty();
                        $("#ul_select2").append(_html);
                        var selecttext = $('#shiju2 > .shiju_lf');
                        var selectmain = $('#ul_select2');
                        var lis=selectmain.find('li');
                        for(var i=0;i<lis.length;i++)
                        {
                            lis[i].onclick=function(){
                                var v=$(this).attr("value");
                                searchNext(v,530);
                                $("#fj").val(v);
                                var textval = $(this).html();
                                selectmain.hide();
                                selecttext.text(decodeURIComponent(textval));
                            }
                        }
                        $("#ul_select2 > li").click(function(){
                            $("#ul_select2").slideUp("slow");
                            $("#ul_select1").fadeOut("fast");
                            $("#ul_select4").fadeOut("fast");
                        });
                        $("#pcs").val("");
                    }else{
                        $("#ul_select4").empty();
                        $("#ul_select4").append(_html);
                        var selecttext = $('#shiju4 > .shiju_lf');
                        var selectmain = $('#ul_select4');
                        var lis=selectmain.find('li');
                        for(var i=0;i<lis.length;i++)
                        {
                            lis[i].onclick=function(){
                                var v=$(this).attr("value");
                                $("#pcs").val(v);
                                var textval = $(this).html();
                                selectmain.hide();
                                selecttext.text(decodeURIComponent(textval));
                            }
                        }
                        $("#ul_select4 > li").click(function(){
                            $("#ul_select4").slideUp("slow");
                            $("#ul_select1").fadeOut("fast");
                            $("#ul_select2").fadeOut("fast");
                        });
                    }
                }


            }
        }
    });
}
/**
 * 特殊部门 梅河口和公主领
 * @param parentCode
 * @param code
 */
function specilDept(parentCode,code){
    $.ajax({
        url :uploadUrl+"/api/v2/xrxq/getDept/"+code+"/"+parentCode,
        type : "get",
        dataType : "json",
        success : function(resp){
            if(resp&&resp.succ){
                var _data = resp.data;
                var _html="";
                for(var i=0;i<_data.length;i++){
                    var _item = _data[i];
                    _html += "<li value='"+_item.guid+"'>" + _item.orgName + "</li>"
                }
                    $("#ul_select4").empty();
                    $("#ul_select4").append(_html);
                    var selecttext = $('#shiju4 > .shiju_lf');
                    var selectmain = $('#ul_select4');
                    var lis=selectmain.find('li');
                    for(var i=0;i<lis.length;i++)
                    {
                        lis[i].onclick=function(){
                            var v=$(this).attr("value");
                            $("#pcs").val(v);
                            var textval = $(this).html();
                            selectmain.hide();
                            selecttext.text(decodeURIComponent(textval));
                        }
                    }
                    $("#ul_select4 > li").click(function(){
                        $("#ul_select4").slideUp("slow");
                        $("#ul_select1").fadeOut("fast");
                        $("#ul_select2").fadeOut("fast");
                    });
                }

            }

    });

}